#include "niveau.h"


int charger_niveau(int grille [][nbre_case])
{
    FILE *f;
    int i,j;
    char chemin[]="niveau_de_jeux.lvl";
    char ligne[nbre_case*nbre_case+1]={0};
    f=fopen(chemin,"r");
    if (f==NULL)return(0);
    else
    {
        fgets(ligne,nbre_case*nbre_case+1,f);
        for (i=0;i<nbre_case;i++)
        {
            for(j=0;j<nbre_case;j++)
            {
                switch (ligne[(i*nbre_case)+j])
                {
                case '0': grille[j][i]=0; break;
                case '1': grille[j][i]=1; break;
                case '2': grille[j][i]=2; break;
                case '3': grille[j][i]=3; break;
                case '4': grille[j][i]=4; break;
                }

            }

        }

        fclose(f);
        return(1);
    }

}

int sauvegarder_nieau (int grille [][nbre_case])
{
int i,j;
FILE *f;
char chemin[]="sauvegarde_niveau.lvl";
f=fopen(chemin,"w");
if (f==NULL) return (0);
    else
{
    for (i=0;i<nbre_case;i++)
  {
      for (j=0;j<nbre_case;j++)
      {
        fprintf(f,"%d",grille[i][j]);
      }
  }
  fclose(f);
  return(1);
}
}
